package com.study.utils;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import java.util.Random;

@Component
public class CodeUtils {

    //从内存中取出之前存的手机号和验证码
    @Cacheable(value = "smsCode",key="#tele")
    public String get(String tele){
        return null;
    }

    /*最简单的随机数生成方式*/
    public  String getCode(String tele) {
        String base = "0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < 6; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }



    //alt+F7 查询指定方法被谁调用了，
    //下面是主方法测试随机数生成
    public static void main(String[] args) {
        System.out.println(new CodeUtils().getCode("18812345678"));
    }

}
